import reqwest from "reqwest"
import reqwest from "Immutable"
export const FETCH_CITYS = 'FETCH_CITYS'
export const FETCH_COMMS = 'FETCH_COMMS'
export const FETC_DISTRICTS = 'FETCH_COMMS'


export function fetchCitys(){
  return (dispatch)=>{
    reqwest({
      url:"/api/findCity"
    }).then(data=>dispatch({
      type:FETCH_CITYS,
      citys:Immutable.List(data.data.map((city)=>({
        id:city.id,
        name:city.name
      })))
    }))
  }
}

export function fetchCitysIfNeed(){
  return (dispatch,getState)=>{
    if(getState().getIn(["city","citys"]).isEmpty()){
      dispatch(fetchCitys())
    }
  }
}
